<template>
  <view class="template-course tn-safe-area-inset-bottom">
    <swiper class="card-swiper" :circular="true"
      :autoplay="true" duration="5000" interval="5000" @change="cardSwiper"> 
      <swiper-item v-for="(item,index) in swiperList" :key="index" :class="cardCur==index?'cur':''">
        <view class="swiper-item image-banner">
          <image :src="item.url" mode="aspectFill" v-if="item.type=='image'"></image>
        </view>
      </swiper-item>
    </swiper>
    <view class="indication">
        <block v-for="(item,index) in swiperList" :key="index">
            <view class="spot" :class="cardCur==index?'active':''"></view>
        </block>
    </view>
   
    <view class="tn-flex tn-flex-row-between tn-margin tea-user__wrap">
      
      <view class="tn-flex-3 tn-padding tea-radius tn-bg-white tea-shadow" style="margin-right: 30rpx;">
        <view class="tn-flex">
          <view class="tn-flex tn-flex-row-center tn-flex-col-center">
            <view class="user-avatar">
							<tn-avatar :src="userInfo.avatar" size="lg" imgMode="scaleToFill"></tn-avatar>
            </view>
            <view class="tn-padding-right tn-text-ellipsis tn-text-left">
              <view class="tn-padding-right tn-padding-left-sm tn-color-black tn-text-bold">
                {{userInfo.nickname}}
              </view>
              <view class="tn-padding-right tn-padding-left-sm tn-padding-top-xs tn-color-gray tn-text-sm">欢迎使用兔兔找题答题系统</view>
            </view>
          </view>
        </view>
      </view>
      
      <view class="tn-flex-1 justify-content-item tn-padding tn-text-center tea-radius tn-bg-white tea-shadow" @click="tn('/subpages/user/set')">
        <view class="">
          <text class="tn-icon-edit tn-text-xl"></text>
        </view>
        <view class=" tn-padding-top-xs">
          信息
        </view>
      </view>
    </view>
    
    
    <view class="">
      
      <!-- 方式12 start-->
      <view class="tn-flex tn-margin" style="padding-top: 15rpx;">
        <view class="tn-flex-1 tea-shadow tea-radius tn-bg-white" style="margin-right: 15rpx;padding: 40rpx 0;" @click="tn('/subpages/exam/rank/list')">
          <view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
            <view class="icon12__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-main-gradient-blue--light tn-color-blue">
              <view class="tn-icon-trophy tn-three"></view>
            </view>  
            <view class="tn-text-center">
              <view class="tn-text-ellipsis tn-text-xl tn-text-bold">答题排行</view>
              <view class="tn-text-ellipsis tn-color-gray--dark tn-padding-top-sm">猜猜你再第几位</view>
            </view>
          </view>
        </view>
        <view class="tn-flex-1 tea-shadow tea-radius tn-bg-white" style="margin-left: 15rpx;padding: 40rpx 0;" @click="tn('/subpages/user/index')">
          <view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
            <view class="icon12__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-main-gradient-blue--light tn-color-blue">
              <view class="tn-icon-menu-match tn-three"></view>
            </view>  
            <view class="tn-text-center">
              <view class="tn-text-ellipsis tn-text-xl tn-text-bold">个人中心</view>
              <view class="tn-text-ellipsis tn-color-gray--dark tn-padding-top-sm">瞧瞧你的主页</view>
            </view>
          </view>
        </view>
      </view>
      
			<!-- 中间卡片开始 -->
      <view class="tn-info__container tn-flex tn-flex-wrap tn-flex-col-center tn-flex-row-between tn-margin" style="padding-top: 15rpx;">
        <block v-for="(item, index) in tuniaoData" :key="index">
          <view class="tn-info__item tn-flex tn-flex-direction-row tn-flex-col-center tn-flex-row-between tn-color-white tea-shadow" @click="tn(item.url)">
            <view class="tn-info__item__left tn-flex tn-flex-direction-row tn-flex-col-center tn-flex-row-left">
              <view class="tn-info__item__left--icon tn-flex tn-flex-col-center tn-flex-row-center" :class="[`tn-color-${item.color}--disabled`]">
                <view :class="[`tn-icon-${item.icon}`]"></view>
              </view>
              <view class="tn-info__item__left__content">
                <view class="tn-info__item__left__content--title tn-text-bold tn-text-xl tn-color-black">{{ item.title }}</view>
                <view class="tn-info__item__left__content--data tn-padding-top-xs tn-color-black">
                {{ item.value }}
                <text class="tn-padding-left-xs"></text>
                </view>
              </view>
            </view>
            <view class="tn-info__item__right">
              <view class="tn-info__item__right--icon">
                <view :class="[`tn-icon-${item.icon}`]"></view>
              </view>
            </view>
          </view>
        </block>
      </view>
			<!-- 中间卡片结束 -->
			
			<!-- 文档开始 -->
			<view class="tn-margin"  style="box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.07);">
				<view class="tn-flex-row-between tn-strip-top tn-padding tn-strip-bottom-min tn-margin-top-xs">
				  <view class="justify-content-item">
				    <view class="tn-text-bold tn-text-lg">
				      {{articleList.title}}
				    </view>
				  </view>
				</view>
				<view class="tn-flex tn-flex-row-between tn-strip-bottom-min tn-padding" style="padding-top: 10rpx;padding-bottom: 20rpx;" v-for="(item1, index) in articleList.list" :key="index" @click="tn('/subpages/article/content?uid=' + item1.uid)">
				  <view class="justify-content-item">
				    <view class="tn-text-df">
				      {{ item1.title }}
				    </view>
				  </view>
				</view>
			</view>
			<!-- 文档结束 -->
			
    </view>
        
  </view>
</template>

<script>
  import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import { userLogin } from '@/utils/api/user'
  export default {
    name: 'TemplateCourse',
    mixins: [template_page_mixin],
    data(){
      return {
        cardCur: 0,
        swiperList: [{
          id: 0,
          type: 'image',
          url: 'http://qiniucloud.qqdeveloper.com/202309122353528.jpg',
        }, {
          id: 1,
          type: 'image',
          url: 'http://qiniucloud.qqdeveloper.com/202309122353596.jpg',
        }, {
          id: 2,
          type: 'image',
          url: 'http://qiniucloud.qqdeveloper.com/202309122353612.jpg',
        }, {
          id: 3,
          type: 'image',
          url: 'http://qiniucloud.qqdeveloper.com/202309122353612.jpg',
        }, {
          id: 4,
          type: 'image',
          url: 'http://qiniucloud.qqdeveloper.com/202309122353630.jpg',
        }],
        tuniaoData: [
          {
            title: '中秋答题',
            icon: 'order-fill',
            color: 'red',
            value: '家人团圆',
						url: '/subpages/exam/list/activity_list'
          },
          {
            title: '常规答题',
            icon: 'tag-fill',
            color: 'blue',
            value: '海量题库',
						url: '/subpages/exam/list/list'
          },
          {
            title: '关于兔兔',
            icon: 'bookmark-fill',
            color: 'orange',
            value: '了解兔兔',
						url: '/subpages/help/content?uid=535853725114657278'
          },
          {
            title: '答题事项',
            icon: 'tip-fill',
            color: 'green',
            value: '答题规范',
						url: '/subpages/help/content?uid=542677197699339071'
          },
					{
					  title: '商务合作',
					  icon: 'identity-fill',
					  color: 'teal',
					  value: '联系兔兔',
						url: '/subpages/help/content?uid=535853809962432024'
					},
					{
					  title: '兔兔社群',
					  icon: 'wechat-fill',
					  color: 'aquablue',
					  value: '加入社群',
						url: '/subpages/help/content?uid=542754200506571780'
					}
        ],
				articleList: {
					uid: "",
					title: "答题技巧",
					list: [
						{
							uid: "535843466751545307",
							title: "PHPPHP三大主流框架实现统一日志功能",
						},
						{
							uid: "535847751672867770",
							title: "PHPGo语言中的内存逃逸问题分析与解决",
						},
						{
							uid: "535849796574073086",
							title: "PHPGo语言切片底层原理深度剖析",
						},
					],
				},
				userInfo: {
					nickname: '匿名用户',
					avatar: 'http://qiniucloud.qqdeveloper.com/xiaomai1.jpg',
				},
      }
    },
		onShow() {
			this.userLogin()
		},
    methods: {
      cardSwiper(e) {
        this.cardCur = e.detail.current
      },
			tn(e) {
				this.$func.navigatorTo(e)
			},
			userLogin() {
				let _that = this
				if (uni.getStorageSync('avatar') != '') {
					_that.userInfo.avatar = uni.getStorageSync('avatar') || 'http://qiniucloud.qqdeveloper.com/xiaomai1.jpg'
					_that.userInfo.nickname = uni.getStorageSync('nickname') || '匿名用户'
				} else {
					let sysInfo = {}
					uni.getSystemInfo({
						success(res) {
							sysInfo = res
						}
					})
					uni.login({
						provider: 'weixin',
						success(res) {
							userLogin({
								code: res.code,
								sysInfo: sysInfo
							}).then(res => {
								if (res.code === 100) {
									uni.setStorageSync('avatar', res.data.avatar)
									uni.setStorageSync('nickname', res.data.nickname)
									uni.setStorageSync('token', res.data.token)
									_that.userInfo.nickname = res.data.nickname
									_that.userInfo.avatar = res.data.avatar
								}
							})
						},
					})
				}
			},
    }
  }
</script>

<style lang="scss" scoped>
  /* 头像 start*/
  .user-avatar{
    width: 90rpx;
    height: 90rpx;
    border-radius: 50%;
    overflow: hidden;
  }
  /* 内容布局 start*/
  .tea-shadow{
    box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.07);
  }
  .tea-user {
    
    &__wrap {
      position: relative;
      z-index: 1;
      margin: 20rpx 30rpx;
      margin-top: -80rpx;
    }
  }
  .tea-radius{
    border-radius: 15rpx;
  }
  
  /* 轮播视觉差 start */
  .card-swiper {
    height: 400rpx !important;
  }
    
  .card-swiper swiper-item {
    width: 750rpx !important;
    left: 0rpx;
    box-sizing: border-box;
    // padding: 0rpx 30rpx 90rpx 30rpx;
    overflow: initial;
  }
    
  .card-swiper swiper-item .swiper-item {
    width: 100%;
    display: block;
    height: 100%;
    transform: scale(1);
    transition: all 0.2s ease-in 0s;
    overflow: hidden;
  }
    
  .card-swiper swiper-item.cur .swiper-item {
    transform: none;
    transition: all 0.2s ease-in 0s;
  }
  
  .image-banner{
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .image-banner image{
    width: 100%;
    height: 100%;
  }
  
  /* 轮播指示点 start*/
  .indication{
    z-index: 9999;
    width: 100%;
    height: 36rpx;
    position: absolute;
    display:flex;
    flex-direction:row;
    align-items:center;
    justify-content:center;
  }
  
  .spot{
    background-color: #FFFFFF;
    opacity: 0.6;
    width: 10rpx;
    height: 10rpx;
    border-radius: 20rpx;
    top: -130rpx;
    margin: 0 8rpx !important;
    position: relative;
  }
  
  .spot.active{
    opacity: 1;
    width: 30rpx;
    background-color: #FFFFFF;
  }
  
  /* 图标容器12 start */
  .tn-three{
      position: absolute;
      top: 48%;
      right: 50%;
      bottom: 50%;
      left: 52%;
      transform: translate(-38rpx, -16rpx) rotateX(0deg) rotateY(10deg) rotateZ(-20deg);
      text-shadow: -1rpx 2rpx 0 #f0f0f0, -2rpx 4rpx 0 #f0f0f0, -10rpx 20rpx 30rpx rgba(0, 0, 0, 0.2);
  }
  .icon12 {
    &__item {
      width: 30%;
      background-color: #FFFFFF;
      border-radius: 10rpx;
      padding: 30rpx;
      margin: 20rpx 10rpx;
      transform: scale(1);
      transition: transform 0.3s linear;
      transform-origin: center center;
      
      &--icon {
        width: 100rpx;
        height: 100rpx;
        font-size: 60rpx;
        border-radius: 50%;
        margin-bottom: 18rpx;
        position: relative;
        z-index: 1;
        
        &::after {
          content: " ";
          position: absolute;
          z-index: -1;
          width: 100%;
          height: 100%;
          left: 0;
          bottom: 0;
          border-radius: inherit;
          opacity: 1;
          transform: scale(1, 1);
          background-size: 100% 100%;
          background-image: url(https://tnuiimage.tnkjapp.com/cool_bg_image/icon_bg.png);
        }
      }
    }
  }
  /* 业务展示 start */
  .tn-info {
    
    &__container {
      margin-top: 10rpx;
      margin-bottom: 50rpx;
    }
    
    &__item {
      width: 48%;
      margin: 15rpx 0rpx;
      padding: 40rpx 30rpx;
      border-radius: 15rpx;
      
  
        position: relative;
        z-index: 1;
        
        &::after {
          content: " ";
          position: absolute;
          z-index: -1;
          width: 100%;
          height: 100%;
          left: 0;
          bottom: 0;
          border-radius: inherit;
          opacity: 1;
          transform: scale(1, 1);
          background-size: 100% 100%;
          background-image: url(https://tnuiimage.tnkjapp.com/cool_bg_image/6.png);
        }
      
      &__left {
        
        &--icon {
          width: 80rpx;
          height: 80rpx;
          border-radius: 50%;
          font-size: 70rpx;
          margin-right: 20rpx;
          position: relative;
          z-index: 1;
        }
        
        &__content {
          font-size: 30rpx;
          
          &--data {
            margin-top: 5rpx;
						font-size: 24rpx;
            // font-weight: bold;
          }
        }
      }
      
      &__right {
        &--icon {
          position: absolute;
          right: 0upx;
          top: 50upx;
          font-size: 100upx;
          width: 108upx;
          height: 108upx;
          text-align: center;
          line-height: 60upx;
          opacity: 0.1;  
        }
      }
    }
  }
  /* 业务展示 end */
</style>
